{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7882fa0f",
   "metadata": {},
   "source": [
    "### P037 多项式特征 - 单个变量的多项式特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5c1bbe73",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import PolynomialFeatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "99f62dac",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame(\n",
    "    data = np.arange(10),\n",
    "    columns = [\"x\"]\n",
    ")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf636ed3",
   "metadata": {},
   "outputs": [],
   "source": [
    "poly = PolynomialFeatures(degree=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "743328e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_poly = poly.fit_transform(df)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "34e7bf30",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_poly"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74d06f27",
   "metadata": {},
   "source": [
    "### P038 多项式特征 - 多个变量的多项式特征"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "53c27979",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import PolynomialFeatures"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ecfd2145",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.DataFrame({\n",
    "    \"x\": np.arange(10),\n",
    "    \"y\": np.arange(10, 20)\n",
    "})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d86e3d2c",
   "metadata": {},
   "outputs": [],
   "source": [
    "poly = PolynomialFeatures(degree=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3577d5a4",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_poly = poly.fit_transform(df).astype(int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f2aa9f57",
   "metadata": {},
   "outputs": [],
   "source": [
    "df_poly"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9f103001",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
